﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ninject;
using System.Web.Routing;
using System.Web.Mvc;
using BudgetMealsModels.Abstract;
using BudgetMealsModels.Concrete;

namespace BudgetMealsUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel kernel;

        public NinjectControllerFactory()
        {
            kernel = new StandardKernel();

            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)kernel.Get(controllerType);
        }

        public void AddBindings()
        {
            kernel.Rebind<IUserRepository>().To<EFDbUserRepository>();
            kernel.Rebind<IMealRepository>().To<EFMealRepository>();
            kernel.Rebind<IRecipeRepository>().To<EFDbRecipeRepository>();
            kernel.Rebind<ICommentRepository>().To<EFDbCommentRepository>();
        }
    }
}